package com.prd.controller;

import com.prd.dto.*;
import com.prd.model.EntMeetSummary;
import com.prd.service.EntMeetSummaryService;
import com.prd.util.AjaxResult;
import com.prd.util.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "会议纪要/决议")
@RestController
@RequestMapping("/api/entMeetSummary")
public class EntMeetSummaryController extends BaseController {

    @Autowired
    private EntMeetSummaryService entMeetSummaryService;

    @ApiOperation("会议纪要/决议审核确认")
    @PostMapping(value = "checkSummary/{summaryId}", produces = "application/json;charset=UTF-8")
    public AjaxResult checkSummary(@PathVariable Long summaryId) {
        return toAjax(entMeetSummaryService.checkSummary(summaryId));
    }

    @ApiOperation("修改会议纪要/决议")
    @PostMapping(value = "updateSummary", produces = "application/json;charset=UTF-8")
    public AjaxResult updateSummary(@RequestBody EntMeetSummary entMeetSummary) {
        return toAjax(entMeetSummaryService.updateSummary(entMeetSummary));
    }

    @ApiOperation("删除会议纪要/决议")
    @PostMapping(value = "deleteSummary/{id}", produces = "application/json;charset=UTF-8")
    public AjaxResult deleteSummary(@PathVariable Long id) {
        return toAjax(entMeetSummaryService.removeById(id));
    }

    @ApiOperation("需执行会议纪要/决议")
    @PostMapping(value = "executeSummary/{id}", produces = "application/json;charset=UTF-8")
    public AjaxResult executeSummary(@PathVariable Long id) {
        return toAjax(entMeetSummaryService.executeSummary(id));
    }

    @ApiOperation("赞成")
    @PostMapping(value = "endorse/{summaryId}", produces = "application/json;charset=UTF-8")
    public AjaxResult endorse(@PathVariable Long summaryId) {
        return toAjax(entMeetSummaryService.endorse(summaryId));
    }

    @ApiOperation("反对")
    @PostMapping(value = "against/{summaryId}", produces = "application/json;charset=UTF-8")
    public AjaxResult against(@PathVariable Long summaryId) {
        return toAjax(entMeetSummaryService.against(summaryId));
    }

    @ApiOperation("弃权")
    @PostMapping(value = "vote/{summaryId}", produces = "application/json;charset=UTF-8")
    public AjaxResult vote(@PathVariable Long summaryId) {
        return toAjax(entMeetSummaryService.vote(summaryId));
    }

    @ApiOperation("查询执行/督导列表")
    @GetMapping(value = "listExecuteSummary/{meetId}", produces = "application/json;charset=UTF-8")
    public TableDataInfo listExecute(@PathVariable("meetId") Long meetId, Integer options, Integer perform) {
        startPage();
        List<EntMeetSummary> list = entMeetSummaryService.listExecute(meetId, options, perform);
        return getDataPage(list);
    }

    @ApiOperation("查询会议决议人员权限")
    @GetMapping(value = "jurisdiction/{summaryId}", produces = "application/json;charset=UTF-8")
    public AjaxResult jurisdiction(@PathVariable Long summaryId) {
        return AjaxResult.success(entMeetSummaryService.jurisdiction(summaryId));
    }

    @ApiOperation("执行/督导预完成")
    @PostMapping(value = "advanceSummary/{summaryId}", produces = "application/json;charset=UTF-8")
    public AjaxResult advanceSummary(@PathVariable("summaryId") Long summaryId) {
        return toAjax(entMeetSummaryService.advanceSummary(summaryId));
    }

    @ApiOperation("查询决议详情")
    @GetMapping(value = "listExecuteSummaryDetails/{summaryId}", produces = "application/json;charset=UTF-8")
    public AjaxResult listExecuteSummaryDetails(@PathVariable("summaryId") Long summaryId) {
        return AjaxResult.success(entMeetSummaryService.listExecuteSummaryDetails(summaryId));
    }

    @ApiOperation("同意/不同意会议决议")
    @PostMapping(value = "agreeSummary", produces = "application/json;charset=UTF-8")
    public AjaxResult agreeSummary(@RequestBody EntMeetSummary entMeetSummary) {
        if (entMeetSummary.getId() == null || entMeetSummary.getStatus() == null || StringUtils.isBlank(entMeetSummary.getInstruct())) {
            return AjaxResult.error("参数不能为空！");
        }
        return AjaxResult.success(entMeetSummaryService.agreeSummary(entMeetSummary.getId(), entMeetSummary.getStatus(), entMeetSummary.getInstruct()));
    }

    @ApiOperation("添加执行汇报信息")
    @PostMapping(value = "addReport", produces = "application/json;charset=UTF-8")
    public AjaxResult addReport(@RequestBody ReportDto reportDto) {
        return toAjax(entMeetSummaryService.addReport(reportDto));
    }

    @ApiOperation("添加补充执行汇报信息")
    @PostMapping(value = "addReplenish", produces = "application/json;charset=UTF-8")
    public AjaxResult addReplenish(@RequestBody ReplenishReportDto replenishReportDto) {
        return toAjax(entMeetSummaryService.addReplenish(replenishReportDto));
    }

    @ApiOperation("添加不合格原因信息")
    @PostMapping(value = "addQualified", produces = "application/json;charset=UTF-8")
    public AjaxResult addQualified(@RequestBody QualifiedDto qualifiedDto) {
        return toAjax(entMeetSummaryService.addQualified(qualifiedDto));
    }

    @ApiOperation("添加执行完成信息")
    @PostMapping(value = "addFulfill", produces = "application/json;charset=UTF-8")
    public AjaxResult addFulfill(@RequestBody FulfillDto fulfillDto) {
        return toAjax(entMeetSummaryService.addFulfill(fulfillDto));
    }

    @ApiOperation("决议任务驳回/完成")
    @PostMapping(value = "taskReject/{summaryId}/{examine}", produces = "application/json;charset=UTF-8")
    public AjaxResult taskReject(@PathVariable("summaryId") Long summaryId, @PathVariable("examine") Integer examine) {
        return toAjax(entMeetSummaryService.taskReject(summaryId, examine));
    }
}
